﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using DataAccess;

namespace Controller
{
    public class GetTableListController
    {
        public event GetTableListEventHandler GetTableListCompleted;

        public void OnGetTableListCompleted(GetTableListEventArgs e)
        {
            if (GetTableListCompleted != null)
                GetTableListCompleted(e);
        }

        public void GetTableList(ConnectionInformation CI)
        { 
            List<string> result = new List<string>();
          
            try
            {
                if (CI.DataBaseType == DataBaseType.MSSQLServer)
                {
                    MSSQLDataAccess mSSQLDataAccess = new MSSQLDataAccess();
                    result=mSSQLDataAccess.GetTableList(CI);
                }
                else if (CI.DataBaseType == DataBaseType.MSAccess)
                {
                    MSAccessDataAccess mSAccessDataAccess = new MSAccessDataAccess();
                    result = mSAccessDataAccess.GetTableList(CI);
                }
                else if (CI.DataBaseType == DataBaseType.MySQL)
                {
                    MySQLDataAccess mySQLDataAccess = new MySQLDataAccess();
                    result = mySQLDataAccess.GetTableList(CI);
                }
                OnGetTableListCompleted(new GetTableListEventArgs(result));
            }

            catch (Exception ex)
            {
                OnGetTableListCompleted(new GetTableListEventArgs(ex));
            }
        }
    }
}
